home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
TextFormatter.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-08
|
3KB
|
145 lines
#ifndef TextFormatter_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define TextFormatter_First
#include "Object.h"
#include "Font.h"
#include "Mark.h"
//---- descriptor of a text line -----------------------------------------
struct LineDesc {
int lnAscent;
int lnHeight;
LineDesc(int b= 0, int h= 0);
void Reset();
bool IsEqual(LineDesc l);
void Max(Font *f);
void Max(LineDesc ld);
void Max(int ascent, int height);
void FromFont(Font *f);
int Height();
int Base();
};
//---- line mark ------------------------------------------------------------
struct LineMark: public Mark {
LineDesc ld;
MetaDef(LineMark);
LineMark(LineDesc ldesc, int pos= 0, int len= 0, eMarkState s= eStateNone);
LineMark();
void ChangeMark(int pos, int len, LineDesc ldesc, eMarkState s= eStateNone);
void Copy(LineMark*);
int Height();
int Base();
bool IsDifferent(LineMark *lm);
};
//---- abstract class TextFormatter ---------------------------------------
class ObjArray;
class Text;
class TextPainter;
class TextFormatter: public Object {
public:
MetaDef(TextFormatter);
TextFormatter();
int Format(Text *, TextPainter *tp, int w, int from, int to);
ObjArray *GetLines();
static void Free();
protected:
static ObjArray *lines;
static int nLines;
void AddBreak(Text *t, TextPainter *tp, int from, int to, LineDesc &ld);
virtual void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
};
//---- SimpleFormatter, break lines only at breaking characters (\n, \r, \f) --
class SimpleFormatter: public TextFormatter {
public:
MetaDef(SimpleFormatter);
SimpleFormatter();
protected:
void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
};
//---- FoldingFormatter, fold lines (preemptive) -------------------------
class FoldingFormatter: public TextFormatter {
public:
MetaDef(FoldingFormatter);
FoldingFormatter();
protected:
void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
void BreakCharacter(Text *t, TextPainter *tp, int at, LineDesc &maxld, int w);
void BreakWord(Text *t, TextPainter *tp, LineDesc &maxld, int w);
void Break(TextPainter *tp, int from, int to, LineDesc &maxld, int w);
private:
Text *text;
int start, end, width, nWords, wx, cx;
};
//---- abstract class TextPager ------------------------------------------
class TextPager: public Object {
public:
MetaDef(TextPager);
TextPager();
virtual Rectangle NextPageBreak(int pn, Rectangle pgr, class StaticTextView *);
virtual void Repaginate(int startAt);
};
//---- abstract class LinePager ------------------------------------------
class LinePager: public TextPager {
public:
LinePager();
Rectangle NextPageBreak(int pn, Rectangle pgr, class StaticTextView *);
};
//---- inlines -----------------------------------------------------------
inline bool LineDesc::IsEqual(LineDesc l)
{
return lnAscent == l.lnAscent && lnHeight == l.lnHeight;
}
inline int LineDesc::Height()
{
return lnHeight;
}
inline int LineDesc::Base()
{
return lnAscent;
}
inline int LineMark::Height()
{
return ld.Height();
}
inline int LineMark::Base()
{
return ld.Base();
}
#endif